﻿using CleanArchitecture.Infrastructure.Entities.AdminUsers;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace CleanArchitecture.Infrastructure.DataMapping.AdminUsers
{
    /// <summary>
    /// Represents a customer password mapping configuration
    /// </summary>
    public partial class AdminUserPasswordMap : NowaEntityTypeConfiguration<AdminUserPassword>
    {
        #region Methods

        /// <summary>
        /// Configures the entity
        /// </summary>
        /// <param name="builder">The builder to be used to configure the entity</param>
        public override void Configure(EntityTypeBuilder<AdminUserPassword> builder)
        {
            builder.ToTable("admin_userpassword");
            builder.HasKey(password => password.Id);

            builder.Property(password => password.Password).HasMaxLength(255);
            builder.Property(password => password.PasswordSalt).HasMaxLength(100);
            builder.Property(mapping => mapping.FkUserId).HasColumnName("Fk_UserId");
            builder.Property(password => password.PasswordStrongLevel).IsRequired();

            builder.HasOne(password => password.AdminUser)
                .WithMany()
                .HasForeignKey(password => password.FkUserId)
                .IsRequired();

            builder.Ignore(password => password.PasswordFormat);

            base.Configure(builder);
        }

        #endregion
    }
}